﻿using System;
using System.IO;
using System.Xml;

namespace NielsHebling.UnitTestResultViewerForSL.Core.Xml
{
    internal class Serializer
    {
        public T ReadXML<T>(string fileName)
        {
            FileInfo fi = new FileInfo(fileName);
            if (fi.Exists)
            {
                try
                {
                    System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(T));
                    FileStream fs = new FileStream(fileName, FileMode.Open);
                    object returnObj = xs.Deserialize(fs);
                    fs.Close();
                    return (T)returnObj;
                }
                catch (Exception)
                {
                    return default(T);
                }
            }
            else
            {
                return default(T);
            }
        }
    }
}
